#ifndef ROSNODE_H
#define ROSNODE_H

#include <QThread>
#include <QImage>
#include <QStringListModel>

#include <ros/ros.h>
#include <std_msgs/UInt8MultiArray.h>
#include <image_transport/image_transport.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include "clustertype.h"
#include "clustermsg.h"

class RosNode : public QThread
{
    Q_OBJECT
public:
    RosNode(int argc, char **argv);
    ~RosNode();

    bool init();
    bool init(const std::string &master_url, const std::string &host_url);
    static void imageCallback(const sensor_msgs::ImageConstPtr& msg);
    void fnCluster_mh_ClusterMsgCB(const std_msgs::UInt8MultiArray::ConstPtr &);

    void run();

    enum LogLevel {DEBUG, INFO, WARN, ERROR, FATAL};

    QStringListModel* logModel() { return &log_model; }
    void rosLog( const LogLevel &level, const std::string &msg);

    QGC_To_Cluster_All stQgcSendMsg;
    Cluster_To_Qgc_All stQgcSaveMsg;
    Cluster_Control_Message operatorMsg;
    static QString s_LogStr;
    static bool s_bIsRosTriggerUiUpdate;
    static bool s_bIsUiUpdateFinished;

    static bool s_bIsRosTriggerMatUpdate;
    static bool s_bIsMatUpdateFinished;

Q_SIGNALS:
    void signalMatUpdate(const cv::Mat &);
    void signalLogUpdated();
    void signalRosTriggerUiUpdate();

public Q_SLOTS:
    void slotRosClose();
    void slotRosActionHandle();

private:
    int rosArgc;
    char **ppRosArgv;
    int rosFrequency;
    QStringListModel log_model;
    int freqDividerCnt;
    ros::Publisher stClusterMsgPub;
    ros::Subscriber stClusterMsgSub;
    ros::Subscriber stClusterDediMsgSub;
    static QString s_strLog;
    static cv::Mat s_Mat;
};

#endif // ROSNODE_H
